<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller as BaseController;
use Encore\Admin\Facades\Admin;
use Illuminate\Http\Request;

/**
 * 控制器基类.
 */
class Controller extends BaseController
{
    protected $server_id;

    /**
     * [__construct 设置gameServer DB].
     *
     * @Author   王文凡
     * @DateTime 2018-06-01
     *
     * @version  1.0
     *
     * @param Request $request [description]
     */
    public function __construct(Request $request)
    {
        $this->server_id = $request->input('server_id') ?: 1;
        setDB($this->server_id);
    }

    /**
     * [script 收件人选择js代码].
     *
     * @Author   王文凡
     * @DateTime 2018-04-13
     *
     * @version  1.0
     */
    protected function roleScript()
    {
        $script = <<<EOF

        var recipient  = $("#recipients").parents('.form-group');
        var level = $("#level_section").parents('.form-group');
        recipient.hide();
        $(".radio-inline").on('click',function(){
            var type = $(this).find('.recipient_type').val();
            if(type == 1){
                 recipient.hide();
                 level.show();
            }else if(type == 0){
                recipient.show();
                level.hide();
            }
        });


EOF;
        Admin::script($script);
    }

    /**
     * 区服渠道筛选事件.
     */
    protected function filterScript()
    {
        $str = <<<EOF
            var channel_id  = $(".channel_id").parents('.form-group');
            var server_id = $(".server_id").parents('.form-group');
            
            $(".type").parents('.radio-inline').on('click',function(){
                var type = $(this).find('.type').val();
                if(type == 1){
                    channel_id.hide();
                    server_id.hide();
                }else if(type == 2){
                    channel_id.show();
                    server_id.hide();
                }else{
                    channel_id.hide();
                    server_id.show();
                }
            });
EOF;
        Admin::script($str);
    }
}
